package com.wanxi.dao.impl;

import com.wanxi.dao.UserDao;
import com.wanxi.entity.UserEntity;
import com.wanxi.util.GetSqlSession;
import com.wanxi.util.JDBC;

import java.util.ArrayList;
import java.util.List;

public class UserImpl implements UserDao {

    @Override
    public int add(UserEntity userEntity) {
//        String sql = "insert into user(username,password) values('" + userEntity.getUsername() + "','" + userEntity.getPassword() + "')";
//        return JDBC.update(sql, new ArrayList<>());
        return GetSqlSession.getSqlSession().insert("com.wanxi.dao.UserDao.add", userEntity);
    }

    @Override
    public int delete(UserEntity userEntity) {
        return GetSqlSession.getSqlSession().delete("com.wanxi.dao.UserDao.delete", userEntity);
    }

    @Override
    public UserEntity findById(UserEntity userEntity) {
        return GetSqlSession.getSqlSession().selectOne("com.wanxi.dao.UserDao.findById", userEntity);
    }

    @Override
    public List<UserEntity> findAll(UserEntity userEntity) {
        return GetSqlSession.getSqlSession().selectList("com.wanxi.dao.UserDao.findAll", userEntity);
    }

    @Override
    public int update(UserEntity userEntity) {
        return GetSqlSession.getSqlSession().update("com.wanxi.dao.UserDao.update", userEntity);
    }

    @Override
    public int count(UserEntity userEntity) {
        return GetSqlSession.getSqlSession().selectOne("com.wanxi.dao.UserDao.count", userEntity);
    }

    @Override
    public UserEntity findByUsernameAndPassword(UserEntity userEntity) {

        return GetSqlSession.getSqlSession().selectOne("com.wanxi.dao.UserDao.findByUsernameAndPassword", userEntity);
    }
}
